package ys

import (
	"encoding/json"
)

// 获取AccessToken
// https://open.ys7.com/doc/zh/book/index/user.html
func (c *Client) GetAccessToken() (ysRsp GetAccessTokenResponse, err error) {
	// 业务逻辑
	body := map[string]interface{}{
		"appKey": c.appKey,
		"appSecret": c.secret,
	}
	bytes, err := c.doPostForm("api/lapp/token/get", body)
	if err != nil {
		return
	}
	// 解析返回值
	err = json.Unmarshal(bytes, &ysRsp)
	return
}

// 获取AccessToken的返回值
type GetAccessTokenResponse struct {
	ResponseModel
	Data GetAccessTokenResponseModel `json:"data"` // 数据
}

type GetAccessTokenResponseModel struct {
	AccessToken string `json:"accessToken"` // 获取的accessToken
	ExpireTime  int64  `json:"expireTime"`  // 具体过期时间，精确到毫秒
}
